<template>
  <div class="myStar">
    <home-page-top/>
    <div>
      <div v-if="total" class="ind-wdsc-wz">
        <ul id="wdsc-lis">
          <li v-for="item in articleData" :key="item.id">
            <a :href="item.url" target="_blank">{{item.title}}</a>
            <p class="ind-wdsc-wz-tip" style="position: relative;">
              <i>{{item.siteName}}</i>
              <img src="../../assets/part-line.png">
              <span>{{item.createTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</span>
              <img src="../../assets/part-line.png">
              <!-- <a target="_blank" href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=www.baidu.com&title=&pics=&summary=">fenxiang</a>
              <a href="javascript:void(0)">
              <span class="bdsharebuttonbox bdshare-button-style0-16" style="position: absolute">
                  <a style="font-size: 13px;margin: 0;margin-right: 6px;line-height: 19px;" href="javascript: vold(0)" class="bds_more" data-cmd="more">分享到</a>
                </span>
              </a> -->
              <span>分享到：</span>
              <span class="bdsharebuttonbox" style="position: absolute;  bottom: -5px;">
                <a @click="shareEvent(item)" class="bds_tsina" data-cmd="tsina" href="#"></a>
                <a @click="shareEvent(item)" class="bds_weixin" data-cmd="weixin" href="#"></a>
                <a @click="shareEvent(item)" class="bds_sqq" data-cmd="sqq" href="#"></a>
                <a @click="shareEvent(item)" class="bds_qzone" data-cmd="qzone" href="#"></a>
                <a @click="shareEvent(item)" class="bds_renren" data-cmd="renren" href="#"></a>
              </span>
            </p>
            <div class="ind-wdsc-wz-qxgz">
              <img src="../../assets/delete.png">
              <a @click="cancelArticle(item)" href="javascript:void(0)">取消收藏</a>
            </div>
          </li>
        </ul>
        <!--** 分页 ***-->
        <laypage :pageSize.sync="pageSize" :total="total" :pageNum.sync="pageNum" @changePage="getArticleList"></laypage>
        <!--** 分页 end ***-->
      </div>
      <div v-if="!total&&!loading" style="padding: 40px;text-align: center;font-size: 16px;color: #999;">
        暂无内容
      </div>
    </div>
  </div>
</template>
<script>
import HomePageTop from '@/components/home-page-top'
import Laypage from '@/components/laypage'
import * as api from '@/service/api'
import $ from 'jquery'
export default {
  title: '用户中心-我的',
  data () {
    return {
      loading: false,
      layerLoading: null,
      articleData: {},
      dataPoints: null,
      globalThis: null,
      pageNum: 1,
      pageSize: 10,
      total: null,
      curShareItem: null,
      height: 20
    }
  },
  components: {
    HomePageTop,
    Laypage
  },
  computed: {
  },
  beforeCreate () {
  },
  created () {
    this.globalThis = window
    this.layerLoad = window.layer.load(0, {
      shade: false
    })
  },
  destroyed () {
    if ($('#js_share').length) {
      $('#js_share').remove()
    }
  },
  mounted () {
    const _this = this
    this.getArticleList()
    if (!window._bd_share_main) {
      setTimeout(() => {
        _this.setup()
      }, 0)
    }
  },
  methods: {
    async getArticleList (page) {
      try {
        this.loading = true
        if (page) {
          this.pageNum = page
        }
        let res = await api.getArticleList({
          userId: this.$store.state.me.user.userId,
          pageNum: this.pageNum,
          pageSize: this.pageSize
        })
        this.articleData = res.data.list
        this.total = res.data.total
        window.layer.close(this.layerLoad)
        this.loading = false
        if (window._bd_share_main) {
          setTimeout(() => {
            window._bd_share_main.init()
          })
        }
      } catch (e) {
        console.log(e)
        this.loading = false
        window.layer.close(this.layerLoad)
      }
    },
    async cancelArticle (item) {
      let that = this
      window.layer.open({
        type: 1,
        offset: 'auto',
        id: 'layerDemo' + 'auto', // 防止重复弹出
        content: '<div style="padding: 20px 100px;">确认取消收藏吗</div>',
        btn: '确认',
        // closeBtn: 1,
        btnAlign: 'c',
        shade: 0,
        yes: function () {
          api.cancelArticle({
            // userId: that.$store.state.me.user.userId,
            // title: item.title,
            articleId: item.articleId,
            type: 2,
            siteId: item.siteId
          })
          that.getArticleList(1)
          window.layer.closeAll()
        }
      })
    },
    shareEvent (item, config) {
      if (item.id) {
        this.curShareItem = item
      }
      if (config) {
        config.bdText = this.curShareItem.title
        config.bdDesc = this.curShareItem.bdDesc
        config.title = this.curShareItem.title
        config.bdUrl = this.curShareItem.url
      }
      return config
    },
    setup () {
      window._bd_share_config = {
        common: {
          'onBeforeClick': this.shareEvent,
          'bdSnsKey': {},
          'bdText': 'bdText',
          'bdDesc': 'bdDesc',
          'title': 'title',
          'bdMini': '2',
          'bdPic': '',
          'bdUrl': '',
          'bdStyle': '0',
          'bdSize': '16'
        },
        share: [{
          'bdSize': 16
        }]
      }
      const s = document.createElement('script')
      s.type = 'text/javascript'
      s.id = 'js_share'
      s.src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)
      document.body.appendChild(s)
    }
  }
}
</script>
<style lang="scss">
.myStar {
}
</style>
